


//
//  FenxiaoCollectionView.m
//  1243
//
//  Created by apple on 16/7/19.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "FenxiaoCollectionView.h"
#import "FenxiaoMainCollectionViewCell.h"

static NSString *identifier = @"CELL";

@interface FenxiaoCollectionView ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>

@end
@implementation FenxiaoCollectionView
{
    UICollectionView *mCollectionView;
}
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
        
        //设置单元格大小
        flowLayout.itemSize = CGSizeMake(WIDTH/3 - 0.5, WIDTH/3 - 0.5);
        flowLayout.minimumInteritemSpacing = 0;
        flowLayout.minimumLineSpacing = 0.5;
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        //边界范围
        flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        //页眉页脚
        //创建集合视图
        mCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, WIDTH/3 * 2) collectionViewLayout:flowLayout];
        mCollectionView.backgroundColor = [UIColor whiteColor];
        //collectionView.backgroundColor = [UIColor whiteColor];
        //设置代理属性
        mCollectionView.dataSource = self;
        mCollectionView.delegate = self;
        mCollectionView.scrollEnabled = NO;
        //注册cell
        [mCollectionView registerClass:[FenxiaoMainCollectionViewCell class] forCellWithReuseIdentifier:identifier];
        mCollectionView.backgroundColor = [UIColor colorWithRed:184/255.0 green:184/255.0 blue:184/255.0 alpha:1];
        
        [self addSubview:mCollectionView];

        
    }
    return self;
}

#pragma mark -- 设置分区数量
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
    
}

#pragma mark -- 设置每个分区单元格数量
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 6;
}

#pragma mark -- 自定义cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    FenxiaoMainCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    NSArray *arr = [NSArray arrayWithObjects:@"fenxiao01",@"fenxiao02",@"fenxiao03",@"fenxiao04",@"fenxiao05",@"fenxiao06", nil];
    NSArray *nameArr = [NSArray arrayWithObjects:@"分销佣金",@"分销订单",@"佣金明细",@"我的团队",@"我的客户",@"推广", nil];
    
    [cell.picImg setImage:[UIImage imageNamed:[arr objectAtIndex:indexPath.row]]];
    cell.titleLB.text = [nameArr objectAtIndex:indexPath.row];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"%ld",indexPath.row);
    if (self.jumpControllerBlock) {
        self.jumpControllerBlock(indexPath.row);
    }
}


@end
